<?php

namespace app\Listeners;

use app\models\MsgHandler;
use yii\base\Component;

class MessListeners extends Component
{
    const BEFORE_SEND = 'before_send_msg';
    const AFTER_SEND = 'after_send_msg';

    /**
     * Notes: 时间注册
     * User: aniu
     * DateTime: 2021/3/27 18:31
     */
    public function registerEventHandler()
    {
        // 事件处理类
        $msgHandler = new MsgHandler();
        //绑定事件时，可以传入第三个参数。该参数值将会保存到Event类的data属性中
        $this->on(self::BEFORE_SEND, [$msgHandler, 'beforeSendMsg'], 'who');
        $this->on(self::AFTER_SEND, [$msgHandler, 'afterSendMsg']);
    }
}